#include <my_header.h>

//-1报错，正常时返回接收到的字节数
int recvn(int netfd, void *buf, int length) {
  int total_received, bytes_received;
  while (total_received < length) {
    bytes_received =
        recv(netfd, buf + total_received, length - total_received, NULL);
    if (bytes_received == -1) {
      perror("recv");
      return -1;
    } else if (bytes_received == 0) {
      printf("recvn done!\n");
      break;
    }
    total_received += bytes_received;
  }

  return total_received;
}
